<template>
  <div id="evaluation-management">
    <evaluation-list></evaluation-list>
  </div>
</template>
<script>
// import AddOrUpdate from './user-management-add-update'
import { getUsersList, removeUser } from '@/api/management.js'
import EvaluationList from '@/views/common/evaluation-common/evaluation-list'
export default {
  data () {
    return {
      form: {
        loginName: '',
        roleId: 0,
        no: ''
      },
      columns: [
        {
          title: '用户名',
          key: 'loginName',
          render: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'person'
                }
              }),
              h('strong', params.row.loginName)
            ])
          }
        },
        {
          title: '所属角色',
          key: 'roleName'
        },
        {
          title: '所属班级',
          key: 'no'
        },
        {
          title: '操作',
          key: 'action',
          width: 150,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.addOrUpdateHandle(params.row)
                    }
                  }
                },
                '修改'
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      this.remove(params.row.id)
                    }
                  }
                },
                '删除'
              )
            ])
          }
        }
      ],
      data: [
        {
          loginName: '管理',
          roleId: 1,
          roleName: '管理',
          password: '123',
          no: ''
        },
        {
          loginName: '张三',
          roleId: 2,
          roleName: '老师',
          password: '123',
          no: ''
        },
        {
          loginName: '李四',
          roleId: 4,
          roleName: '专家',
          password: '123',
          no: ''
        },
        {
          loginName: '王二',
          roleId: 3,
          roleName: '学生',
          password: '123',
          no: '三年二班'
        },
        {
          loginName: '狗蛋',
          roleId: 3,
          roleName: '学生',
          password: '123',
          name: '狗蛋',
          mobile: '13588889999',
          email: 'qq@qq.com',
          no: '三年三班'
        }
      ],
      options: [
        {
          value: 1,
          label: '管理员'
        },
        {
          value: 2,
          label: '教师'
        },
        {
          value: 4,
          label: '专家'
        },
        {
          value: 3,
          label: '学生'
        }
      ],
      addOrUpdateVisible: false,
      pageIndex: 1,
      pageSize: 5,
      totalPage: 0,
      dataListLoading: false
    }
  },
  activated () {
    // this.getUsersList()
  },
  methods: {
    // 删除
    remove (id) {
      this.$Modal.confirm({
        title: '提示',
        content: '<p>是否对该用户进行删除操作</p>',
        loading: true,
        onOk: () => {
          removeUser(id).then(res => {
            if (res.data == 'success') {
              this.$Modal.remove()
              this.$Message.info('用户删除成功')
              this.getUsersList()
            }
          })
        }
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row)
      })
    },
    // 获取表格数据
    getUsersList () {
      const date = []
      // this.form.time.map(item => {
      //   if (item != '') {
      //     date.push(dateFormat(item))
      //   }
      // })
      this.dataListLoading = true
      const params = {
        // userId: this.userId,
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
        loginName: this.form.loginName,
        roleId: this.form.roleId,
        no: this.form.no
      }
      getUsersList(params).then(({ data }) => {
        if (data.rows.length > 0) {
          this.data = data.rows
          this.totalPage = data.total
        } else {
          this.data = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getUsersList()
    },
    roleChange (value) {
      if (!value) {
        this.form.roleId = 0
      }
    }
  },
  watch: {},
  components: {
    EvaluationList
  }
}
</script>
<style lang="scss">
#evaluation-management {
}
</style>
